"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var electron_1 = require("electron");
var path = require("path");
var isDev = process.env.MODE === 'devlopment';
var win;
var iconPath = path.join(__dirname, '../icons/linuxTest.png');
function createWindow() {
    win = new electron_1.BrowserWindow({
        width: 800,
        height: 600,
        // transparent: true,
        frame: false,
        icon: iconPath,
        webPreferences: {
            preload: path.join(__dirname, 'preload.js'),
            // nodeIntegration: true,
        },
    });
    if (isDev) {
        win.webContents.openDevTools();
        win.loadURL('http://localhost:9090/');
    }
    else {
        win.loadFile(path.join(__dirname, '../dist/index.html'));
    }
    electron_1.ipcMain.on('min', function () {
        win.minimize();
    });
    electron_1.ipcMain.on('max', function () {
        if (win.isMaximized()) {
            win.restore();
        }
        else {
            win.maximize();
        }
    });
    electron_1.ipcMain.on('close', function () {
        // 最小化到托盘
        win.hide();
        // win.close()
    });
}
electron_1.app.whenReady().then(function () {
    createWindow();
    electron_1.app.on('activate', function () {
        if (electron_1.BrowserWindow.getAllWindows().length === 0) {
            createWindow();
        }
    });
    // 托盘相关
    var tray = new electron_1.Tray(iconPath);
    tray.setToolTip('吴昌焕的小工具');
    tray.setContextMenu(electron_1.Menu.buildFromTemplate([
        {
            label: '显示',
            click: function () {
                win.show();
            },
        },
        {
            label: '退出',
            click: function () {
                electron_1.app.quit();
            },
        },
    ]));
    tray.on('double-click', function () {
        console.log('double-click');
        win.show();
    });
    // 注册快捷键
    electron_1.globalShortcut.register('CommandOrControl+F12', function () {
        var focusWin = electron_1.BrowserWindow.getFocusedWindow();
        focusWin && focusWin.webContents.toggleDevTools();
    });
});
electron_1.app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') {
        electron_1.globalShortcut.unregisterAll();
        electron_1.app.quit();
    }
});
